<template>
	<view class="tree-select">
		<view class="component-item">
			<text class="component-item-label">ifun-tree-picker</text>
			<view class="component-item-content">
				<ifun-tree-picker :treeOptions="treeOptions" :data="treeData" lazy :load="handleLoad">

				</ifun-tree-picker>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "tree-picker",
		data() {
			return {
				defaultData: {},
				treeOptions: {
					value: "code",
					label: "label",
					key: "label"
				},
				treeData: [{
						label: "北京",
						code: "01",
						children: [{
							label: "北京",
							code: "01001",
							children: [{
									label: "北京城西",
									code: "01001001",
								},
								{
									label: "北京城东",
									code: "01001002",
								}
							]
						}]
					},
					{
							label: "江苏",
							code: "02",
							children: [{
								label: "南京",
								code: "02001",
							},
							{
								label: "南通",
								code: "02002",
								children: [{
										label: "南通城西",
										code: "02002001",
									},
									{
										label: "南通城东",
										code: "02002003",
									},
									{
										label: "南通城北",
										code: "02002004",
									},
									{
										label: "南通城南",
										code: "02002005",
									}
								]
							}]
						},
				],
			}
		},
		mounted() {
			setTimeout(() => {
				this.defaultData = {
					value: '222',
					label: '节点222'
				}
			}, 1000)
		},
		methods: {
			handleLoad(info,arr,fn){
				console.log(info,arr);
				
				let data = [
					{
						label: "测试懒加载",
						code: "懒加载001",
					},
					{
						label: "测试懒加载",
						code: "懒加载002",
					}
				]
				if(info.code !='02001'){
					data = [];
				}
				fn(data);
			}
		}
	}
</script>

<style>

</style>